<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>layui</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" href="/static/layuimini/lib/layui-v2.6.3/css/layui.css" media="all">
    <link rel="stylesheet" href="/static/layuimini/css/public.css" media="all">
    <style>
        body {
            background-color: #ffffff;
        }
    </style>
</head>
<body>
<form id="userForm" method="post" onsubmit="return false;">
<div class="layui-form layuimini-form" lay-filter="add_ncc">
    <div class="layui-form-item">
        <label class="layui-form-label required">主机名称</label>
        <div class="layui-input-block">
            <input type="text" name="hostname" id="hostname" lay-verify="required" lay-reqtext="主机名称不能为空" placeholder="请输入主机名称" value="" class="layui-input">
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label required">主机IP</label>
        <div class="layui-input-block">
            <input type="text" name="ip_inner" id="ip_inner" lay-verify="required" lay-reqtext="主机IP不能为空" placeholder="请输入主机IP" value="" class="layui-input">
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label required">资产组</label>
        <div class="layui-input-block">
            <select name="servergroup_id" id="servergroup_id" lay-filter="servergroup_id">
            </select>
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label required">主机端口</label>
        <div class="layui-input-block">
            <input type="text" name="port" id="port" lay-verify="required" lay-reqtext="主机端口不能为空" placeholder="请输入主机端口" value="" class="layui-input">
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label required">资产用户</label>
        <div class="layui-input-block">
            <select name="serveruser_id" id="serveruser_id" lay-filter="serveruser_id">
            </select>
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label required">操作系统</label>
        <div class="layui-input-block">
            <select name="os_status" id="os_status" lay-filter="os_status">
            </select>
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label required">机器类型</label>
        <div class="layui-input-block">
            <select name="system_status" id="system_status" lay-filter="system_status">
            </select>
        </div>
    </div>

    <div class="layui-form-item layui-form-text">
        <label class="layui-form-label"></label>
       <button class="layui-btn" lay-filter="AddHost" type="submit" lay-submit >立即提交</button>
    </div>

</div>
</form>

<script src="/static/layuimini/lib/layui-v2.6.3/layui.js" charset="utf-8"></script>

<script>
    layui.use('form',function () {
        form = layui.form;
        $ = layui.$;
        form.render();
        //监听提交
        form.on('submit(AddHost)', function (data) {
            //发异步，把数据提交
            var hostname = data.field.hostname;
            var servergroup_id = data.field.servergroup_id;
            var ip_inner = data.field.ip_inner;
            var port = data.field.port;
            var serveruser_id = data.field.serveruser_id;
            var os_status = data.field.os_status;
            var system_status = data.field.system_status;

            //alert(JSON.stringify(data));

            $.ajax({
                type: 'post',
                url: "/resources/servers/create/",
                data: {hostname: hostname,servergroup_id:servergroup_id,ip_inner:ip_inner,
                       port: port,serveruser_id:serveruser_id,os_status:os_status,
                       system_status: system_status
                      },
                success: function (res) {
                    if (res.status == 0) {
                        layer.alert(res.msg, {icon: 6}, function () {
                            // 获得frame索引
                            var index = parent.layer.getFrameIndex(window.name);
                            //关闭当前frame
                            parent.layer.close(index);
                           //刷新页面
                            parent.location.reload();
                        });
                         //parent.layer.reload();

                    } else {
                        layer.alert(res.msg, {icon: 5}, function () {
                            // 获得frame索引
                            var index = parent.layer.getFrameIndex(window.name);
                            //关闭当前frame
                            parent.layer.close(index);
                            //刷新页面
                            parent.location.reload();
                        });
                    }
                }
            });
            return false;
        });

    });

</script>
</body>
</html>